diff options
| author | Sebastien Castiel <sebastien@castiel.me> | 2023-12-19 09:36:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-19 09:36:40 -0500 |
| commit | 1e66efe5169dfad9a0c62ba42fbf31ce977bf49e (patch) | |
| tree | 3c2ea81a8b2dd9ba989855de553d65b1bb90b7ad /src/app/groups/[groupId]/expenses/actions.ts | |
| parent | 66ab0ff82bbcb3294d3a0fb84ae5ffcae9910e26 (diff) | |
Use modal dialogs for expense creation & edition (#10)
* First attemps at using route interception and modals
* Remove route interception
* Make it work
* Use Vaul on small screens
* Improve vaul
Diffstat (limited to 'src/app/groups/[groupId]/expenses/actions.ts')
| -rw-r--r-- | src/app/groups/[groupId]/expenses/actions.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/app/groups/[groupId]/expenses/actions.ts b/src/app/groups/[groupId]/expenses/actions.ts new file mode 100644 index 0000000..31bb2e7 --- /dev/null +++ b/src/app/groups/[groupId]/expenses/actions.ts @@ -0,0 +1,28 @@ +'use server' +import { createExpense, deleteExpense, updateExpense } from '@/lib/api' +import { expenseFormSchema } from '@/lib/schemas' +import { revalidatePath } from 'next/cache' + +export async function createExpenseAction(groupId: string, values: unknown) { + 'use server' + const expenseFormValues = expenseFormSchema.parse(values) + await createExpense(expenseFormValues, groupId) + revalidatePath(`/groups/${groupId}`, 'layout') +} + +export async function updateExpenseAction( + groupId: string, + expenseId: string, + values: unknown, +) { + 'use server' + const expenseFormValues = expenseFormSchema.parse(values) + await updateExpense(groupId, expenseId, expenseFormValues) + revalidatePath(`/groups/${groupId}`, 'layout') +} + +export async function deleteExpenseAction(groupId: string, expenseId: string) { + 'use server' + await deleteExpense(expenseId) + revalidatePath(`/groups/${groupId}`, 'layout') +} |
